/**
 * 
 */
package com.eagle.coders.reporting.engine;

import java.io.InputStream;
import java.io.Serializable;
import java.util.Map;

//import org.apache.tools.ant.taskdefs.MatchingTask;
//import org.apache.tools.ant.util.SourceFileScanner;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

import com.eagle.coders.reporting.Report;
import com.eagle.coders.reporting.ReportType;
import com.eagle.coders.reporting.annotation.JasperReporting;
import com.eagle.coders.reporting.exception.ReportException;

/**
 * @author Anees
 * 
 */
@JasperReporting
public class JasperReportEngine implements Report {
	

	@Override
	public Serializable generateReport(
			Map<String, Object> parameters, String reportName,
			ReportType reportType) throws ReportException {
		
		return null;
	}

	@Override
	public Serializable generateReport(
			Map<String, Object> parameters, String reportName,
			String reportPath, ReportType reportType) throws ReportException  {
		try{
			JasperReport jasperReport = JasperCompileManager.compileReport(reportPath);
			
			JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
			
			return jasperPrint;
			
		}catch(JRException e){
			throw new ReportException(e.getMessage());
		}
		
	}

	/**
	 * 
	 */
	@Override
	public Serializable generateReport(
			Map<String, Object> parameters, String reportName,
			InputStream fileInputStream, ReportType reportType) throws ReportException {

		try{
			
			JasperReport jasperReport = JasperCompileManager.compileReport(fileInputStream);
			
			if(!reportType.equals(ReportType.PRINT)){
				return JasperFillManager.fillReport(jasperReport, parameters);
			}else{
				
			}
			return null;

		}catch(JRException e){
			throw new ReportException(e.getMessage());
		}
	}
	
	/**
	 * 
	 * @param sourcePath
	 * @return
	 */
	private Map<String, String> scanReportSourcePath(final String sourcePath){
		
		return null;
	}
}